﻿<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="EntityModel" xmlns="http://ibatis.apache.org/mapping"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

	<alias>
		<!--类的别名-->
		<typeAlias alias="Day" type="ConsoleApp.Dapper.Day,WebApp"/>
	</alias>

	<resultMaps>
		<!--Day类与db表的映射-->
		<resultMap id="SelectAllDayResult" class="Day">
			<result property="AutoId" column="AutoId"/>
			<result property="DayName" column="DayName"/>
		</resultMap>
	</resultMaps>

	<statements>

		<!--查询所有记录-->
		<select id="SelectAllDay" resultMap="SelectAllDayResult" >
			<![CDATA[SELECT * FROM day]]>
		</select>

		<!--查询单条记录-->
		<select id="SelectByKeyId" parameterClass="int" resultMap="SelectAllDayResult" extends="SelectAllDay">
			<![CDATA[ where AutoId = #value#  ]]>
		</select>

		<!--插入新记录-->
		<insert id="InsertDay" parameterClass="Day">
			<![CDATA[INSERT into day(DayName)
			VALUES(#DayName#)]]>
			<selectKey property="AutoId" type="post" resultClass="int">
				select @@identity as value
			</selectKey>
		</insert>

		<!--更新单条记录-->
		<update id="UpdatDay" parameterClass="Day">
			<![CDATA[Update day SET DayName=#DayName#
			Where AutoId=#AutoId#]]>
		</update>

		<!--根据主键删除单条记录-->
		<delete id="DeleteDayById" parameterClass="int">
			<![CDATA[Delete From day Where AutoId=#value#]]>
		</delete>

	</statements>

</sqlMap>